import { defineStore } from 'pinia'

export const useLangStore = defineStore('lang', {
  state: () => ({
    lang: [
      { id: 'cn', name: '中文', active: true, value: 'zh_cn' },
      { id: 'en', name: 'EN', active: false, value: 'en' }
    ]
  }),
  getters: {
    getLang: (state) => state.lang.filter((item) => item.active === true)[0].value
  },
  actions: {
    changeLang(langid) {
      this.lang.forEach((item) => {
        item.id === langid ? (item.active = true) : (item.active = false)
      })
    }
  }
})
